from datetime import timedelta
from pathlib import Path

# 项目所在目录
BASE_DIR = Path(__file__).resolve().parent.parent.parent

# 项目密钥
SECRET_KEY = 'dev'

# json字符串不转码
JSON_AS_ASCII = False

# SQLAlchemy mysql配置参数
SQLALCHEMY_DATABASE_URI = 'mysql://root:123456@127.0.0.1:3306/flask-blog?charset=utf8mb4'
SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_ECHO = True

# jwt配置，token过期时间：120分钟
JWT_SECRET_KEY = 'fr2pK7n6p0idyzoDgrKP'
JWT_ACCESS_TOKEN_EXPIRES = timedelta(minutes=120)

# json序列化配置
JSON_ADD_STATUS = False
JSON_DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
JSON_DATE_FORMAT = '%Y-%m-%d'
JSON_USE_ENCODE_METHODS = True
JSON_DECODE_ERROR_MESSAGE = 'JSON字符串无法解析'

# 缓存配置
CACHE_TYPE = 'SimpleCache'
CACHE_DEFAULT_TIMEOUT = 300  # 默认300秒过期

# 限流器配置
RATELIMIT_ENABLED = True
RATELIMIT_STORAGE_URI = 'memory://'

# IP黑白名单配置
IP_FILTER_ENABLED = True
